<?php
	cria_variaveis($_POST,$_GET,$_FILES); 
?>
<p class="titulo" align="center"><?php echo $msg->get('INTNUM_MSG_02') ?></p>
<p class="subtitulo" align="center"><?php echo $msg->get('INTNUM_MSG_03d') ?></p>
<p>
<div class="tabbar">
    <ul>
    <li><a href="index.php?inc=intnum4.php&modo=material"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material") echo " class=\"tabact\""; ?>><?php echo $msg->get('Material_Teorico') ?></a></li>
    <li><a href="index.php?inc=intnum4.php&modo=exemplo"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") echo " class=\"tabact\""; ?>><?php echo $msg->get('Exemplos_Prontos') ?></a></li>
    <li><a href="index.php?inc=intnum4.php&modo=teclado"<?php if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") echo " class=\"tabact\""; ?>><?php echo $msg->get('Entrada_Teclado') ?></a></li>
    </ul>
</div>
<div id="cas">
<?php
if (!isset($Calcular)) {	
    if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "material")
    {
        require_once("./classes/upload.php");
        $uploads = new Upload();
        $uploads->Lista("integral");
    }
    else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo") { //leitura de dados via banco de dados - modulo de exemplos e exercicios
        include "exibe_prob_intnum4_xml.php";
    }
    else if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "teclado") {
        echo "<form method=post enctype=multipart/form-data action=index.php?opcao=intnum4>";
		echo "<a href=javascript:winopen('ajuda/funcoesphp.php')>".$msg->get('G_MSG_29')."</a>";
		echo "<p>";
		echo $msg->get('INTNUM_MSG_04')."<br><br>";
        echo "f(x)= <input type=text size=60 maxlength=100 name=funcao value=".$funcao."><br>";
        echo "<br>";
        echo $msg->get('INTNUM_MSG_08')."<input type=text size=4 maxlength=4 name=a value=".$a."><br>";
        echo $msg->get('INTNUM_MSG_09')."<input type=text size=4 maxlength=4 name=b value=".$b."><br><br>";
        echo $msg->get('INTNUM_MSG_12d')."<br>";
        echo "n = <input type=text size=4 name=n value=".$n."><br>";
        echo "<p> <p>";
		echo "<p>";
		echo "<input class=button type=submit name=Calcular value=".$msg->get('G_MSG_04').">";
		echo "<br>";
		echo "</form>";
        echo "<form method=post enctype=multipart/form-data action=index.php?opcao=intnum4>";
		echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
		echo "</form>";
    } //end if
} else {
    if (!checaNumerico($a) || !checaNumerico($b) || !checaNumerico($n))
    {
?>
        <p><font color="red"><?php echo $msg->get('Apenas_Dados_Numericos') ?></font></p>
        <p><input type="button" value="<?php echo $msg->get('Voltar') ?>" onclick="history.back()" class="button"></p>
<?php
    }
    else
    {
        if ($_SESSION['ANAWEB']->RetornaModoExecucao() == "exemplo")
            verificaBib($xml_file);
        echo "<br>";
        echo $msg->get('INTNUM_MSG_07')."<br>";
        echo "f(x)= ".$funcao."<br>";
        $funcao_temp = $funcao; // armazena a funcao original para ser utilizada em outros metodos
        echo $msg->get('INTNUM_MSG_08')."".$a."<br>";
        echo $msg->get('INTNUM_MSG_09')."".$b."<br>";
        echo $msg->get('INTNUM_MSG_16d')."".$n."<br>";
        echo "<b>".$msg->get('INTNUM_MSG_14')."</b> <br>";
        $func = normaliza_funcao($funcao);
        $funcao = normaliza_funcao($funcao).";";

        eval ('$x=$a;$fa='.$funcao); //calcula o valor da funcao no ponto x = a
        eval ('$x=$b;$fb='.$funcao); //calcula o valor da funcao no ponto x = b
        $delta=($b-$a)/$n;
        for($i=0;$i<$n-1;$i++){
            eval ('$x=$a+($i+1)*$delta;$v[]='.$funcao);
        }
        $sum=0;
        $sum=$fa+$fb;
        for($i=0;$i<$n-1;$i++){
            $sum=$sum+(2*$v[$i]);
        }
        $aprox=(($b-$a)/(2*$n))*$sum;
        //return $aprox;
        //echo $msg->get('INTNUM_MSG_11')."".trapezio(normaliza_funcao($funcao).';',$a,$b,$n)."<br>";

        echo $msg->get('INTNUM_MSG_11')."".$aprox."<br>";
        echo "<p> <p>";
        // plotar o grafico da funcao
        $funcao = normaliza_funcao($funcao);
        $dados_grafico = "$a|";
        $dados_grafico .= "$b|";
        $dados_grafico .= "$func|";
        $dados_grafico .= "$n|";
        $dados_grafico .= implode("|",$v);
        $arquivo = gera_nome_arquivo();
        $conn = &ADONewConnection($A_DB_TYPE);
        $conn->PConnect($A_DB_HOST,$A_DB_USER,$A_DB_PASS,$A_DB_DB);
        // $conn->debug=1;
        $sql = "INSERT INTO grafico(id,dados) values ('".$arquivo."','".$dados_grafico."');";
        $rs = $conn->Execute($sql);
        if ($rs === false) die(A_LANG_LOGIN_MSG5);
        $rs->Close();
        echo "<table>";
        echo "<tr>";
        echo "<td><img src=intnum_grafico_trapezio.php?arquivo=".$arquivo."  border=0 align=left width=600 height= 400></td>";
        echo "</table>";
        echo "<p><p>";
        echo "<form method=post enctype=multipart/form-data action=index.php?opcao=intnum4>";
        echo "<input class=button type=submit name=Submit value=".$msg->get('G_MSG_03').">";
        echo "</form>";
        if (isset($_POST["navegacao"]) && $_POST["navegacao"] == "sim")
        {
            echo "<form name=\"exemplos\" enctype=\"multipart/form-data\" method=\"post\">";
            echo "<script language=\"javascript\" type=\"text/javascript\">\n";
            echo "function criarLinks(value) {\n";
            echo "document.exemplos.indice.value = value;\n";
            echo "document.exemplos.action = 'index.php?inc=intnum4.php&modo=exemplo'\n";
            echo "document.exemplos.submit();\n";
            echo "}\n";
            echo "</script>";
            echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\">";
            echo "</form>";
            echo $msg->get('Outros_Exemplos')."<br>";
            $objeto = new DOMDocument();
            $objeto->load($xml_file);
            $filho = $objeto->getelementsbytagname("integration");
            if ($filho->length > 0)
            {
                $integrate = $filho->item(0)->getelementsbytagname("integrate");
                $j = 0;
                for ($i = 0; $i < $integrate->length; $i++)
                {
                    if ($j != 0) echo " | ";
                    if ($j == $indice) echo "<b>";
                    echo "<a href=\"javascript:criarLinks($j)\"><u>".($j+1)."</u></a>";
                    if ($j == $indice) echo "</b>";
                    $j++;
                }
            }
        }
            echo "<p>";
        echo $msg->get('G_PROXIMO_EXEMPLO');
        if (!isset($_POST["navegacao"]))
        {
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=intnum1.php>";
            echo "<input type=hidden name=executar value=sim>";
            echo "<input type=hidden name=funcao value=".$funcao_temp.">";
            echo "<input type=hidden name=a value=".$a.">";
            echo "<input type=hidden name=b value=".$b.">";
            echo "<input type=hidden name=n value=".$n.">";
            echo "<input type=hidden name=m value=".$m.">";
        }
        else
        {
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=intnum1.php&modo=exemplo>";
            echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
        }
        echo "<input class=button type=submit name=Submit value='".$msg->get('INTNUM_MSG_03a')."'>";
        echo "</form>";
        if (!isset($_POST["navegacao"]))
        {
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=intnum2.php>";
            echo "<input type=hidden name=executar value=sim>";
            echo "<input type=hidden name=funcao value=".$funcao_temp.">";
            echo "<input type=hidden name=a value=".$a.">";
            echo "<input type=hidden name=b value=".$b.">";
            echo "<input type=hidden name=n value=".$n.">";
        }
        else
        {
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=intnum2.php&modo=exemplo>";
            echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
        }
        echo "<input class=button type=submit name=Submit value='".$msg->get('INTNUM_MSG_03b')."'>";
        echo "</form>";
        if (!isset($_POST["navegacao"]))
        {
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=intnum3.php>";
            echo "<input type=hidden name=executar value=sim>";
            echo "<input type=hidden name=funcao value=".$funcao_temp.">";
            echo "<input type=hidden name=a value=".$a.">";
            echo "<input type=hidden name=b value=".$b.">";
            echo "<input type=hidden name=n value=".$n.">";
        }
        else
        {
            echo "<form method=post enctype=multipart/form-data action=index.php?inc=intnum3.php&modo=exemplo>";
            echo "<input type=\"hidden\" name=\"id_bib\" value=\"".$id_bib."\">";
            echo "<input type=\"hidden\" name=\"xml_file\" value=\"".$xml_file."\">";
            echo "<input type=\"hidden\" name=\"indice\" value=\"$indice\">";
        }
        echo "<input class=button type=submit name=Submit value='".$msg->get('INTNUM_MSG_03c')."'>";
        echo "</form>";
    }
}
?>
</div>